<!--
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-04-12 18:47:17
 * @LastEditTime: 2023-05-23 09:52:58
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 新建 / 编辑 页面
 * @FilePath: \vue3-element-plus-web\src\views\Demo\DrawerNestDemo\components\Drawer\create.vue
 * Copyright 版权声明
-->
<template>
  <div class="">
    <el-form
      :rules="rules"
      ref="dataForm"
      :model="temp"
      label-width="80px"
      style='width:100%;'
    >
      <el-form-item>
        <el-link type="primary" @click="$store.dispatch('ShowDrawer', {
          module: 'DRAWER_NEST_DEMO',
          type: 'DETAIL',
          size: '40%',
          params: {
            row: temp
          }
        }).then(res => {

        })">查看详情</el-link>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <el-link type="primary" @click="$store.dispatch('ShowDrawer', {
          module: 'SYS_ROLE_MANAGE',
          type: 'CREATE',
          size: '40%',
          params: {
            row: temp
          }
        }).then(res => {

        })">创建角色</el-link>
      </el-form-item>
      <el-form-item label="用户名" prop="name">
        <el-input v-model="temp.name" placeholder="请输入用户名"></el-input>
      </el-form-item>

      <el-form-item label="密码" prop="pwd">
        <el-input v-model="temp.pwd" placeholder="请输入密码"></el-input>
      </el-form-item>

      <el-form-item label="序号" prop="orderNum">
        <el-input v-model="temp.orderNum" placeholder="请输入序号0->n"></el-input>
      </el-form-item>

      <el-form-item label="简介" prop="desc">
        <wang-editor
          defaultHtml="<p>老家洛阳</p>"
          @onChange="handleEditorChange"
        >
        </wang-editor>
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-radio-group v-model="temp.status">
          <el-radio
            v-for="item in statusList"
            :key="item.value"
            :label="item.value">
            {{item.label}}
          </el-radio>
        </el-radio-group>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { ENABLED_STATE_ENUM } from '@/config'
import WangEditor from '@/components/WangEditor'

export default {
  name: 'Create',
  computed: {
    ...mapGetters([
      'drawerCurrent'
    ]),
    drawerType: function() {
      return this.drawerCurrent.drawerType
    }
  },
  components: {
    WangEditor
  },
  data() {
    return {
      temp: {
        status: 1
      },
      rules: {
        name: [
          { required: true, message: '请输入用户名', trigger: 'change' },
          { max: 50, message: '用户名最大长度50位', trigger: 'change' }
        ],
        pwd: [
          { required: true, message: '请输入密码', trigger: 'change' },
          { max: 255, message: '密码最大长度255位', trigger: 'change' }
        ],
        orderNum: [
          { required: true, message: '请填写序号', trigger: 'change' }
        ],
        desc: [
          { required: true, message: '请填写简介', trigger: 'change' }
        ]
      },
      // 状态列表
      statusList: ENABLED_STATE_ENUM
    }
  },
  watch: {
    // 表单内容体
    temp: {
      handler: function(val, oldVal) {
      },
      deep: true
    }
  },
  created() {
    // // console.log('-----------', this.drawerCurrent)
    // // 列表传过来的数据
    // const temp = this.drawerCurrent.params.row
    // this.temp = Object.assign({}, this.temp, temp)
    // // *******************如果是 【编辑】 需要从接口数据的话执行一下操作
    // if (this.drawerType === 'UPDATE') {
    //   // drawer loadding 状态 打开
    //   this.$store.dispatch('SetDrawerloading', true)
    //   setTimeout(() => {
    //     // drawer loadding 状态 关闭
    //     this.$store.dispatch('SetDrawerloading', false)
    //   }, 500)
    // }
    console.log('create created')
  },
  mounted() {
    console.log('create mounted')
  },
  activated() {
    console.log('create activated')
  },
  deactivated() {
    console.log('create deactivated')
  },
  methods: {
    // 富文本编辑器内容改变
    handleEditorChange(params) {
      // console.log('富文本内容改变：', params)
      const html = params.html
      this.temp.desc = html
    },
    // 提交表单
    submitForm() {
      return this.$refs['dataForm'].validate()
    },
    // 获取表单数据
    getFormData() {
      return this.temp
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
